PLAT 07 - C++ Precedence Bug
Title Banner


Technical Q&A's


PLAT 07 - C++ Precedence Bug (1-June-95)


Q We're running MPW 3.3.1 with C++ on a Centris 660AV running System 7.5. All the MPW files are from a clean ETO #15.

According to Stroustrup (the C++ programming language) and the K&R C, the precedence of "<" is greater than the precedence of "!=", and all other references that we have agree with this. Since the two tests below return different results, MPW does not appear to be adhering to this rule. Both tests should succeed, but on MPW C++, test 1 fails. Under MPW 'C', this code works as it is supposed to.

-------------------------------------------------------------------------
#include <stdio.h>
main()
{
        puts("Starting Tests...");

        if (1 != 900 < 0)
                puts("Test 1 Worked");
        else
                puts("Test 1 Failed");

        if (1 != (900 < 0))
                puts("Test 2 Worked");
        else
                puts("Test 2 Failed");
}

-------------------------------------------------------------------------


To compile:

 CPlus -o tmp.o tmp.c
 Link -o tmp tmp.o "{CLibraries}"StdClib.o "{CLibraries}"CSANElib.o 6
                   "{CLibraries}"Math.o 6
                "{Libraries}"Runtime.o "{Libraries}"Interface.o 6
                "{Libraries}"ToolLibs.o


A This is a bug, but since MPW is switching over to Mr C (Symantec C++ for MPW) as the main compiler, and this does not occur with SCpp, it is not likely to be fixed (maintenance on CFront has effectively stopped).

You have two choices: either explicitly specify precedence by using (), or switch to SCpp.

Technical Support
Technical Q&As
Previous Question | Contents | Next Question

Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help